home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPBAR.ZIP / APPTOOLS.C < prev    next >
C/C++ Source or Header  |  1993-06-06  |  9KB  |  272 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shellapi.h>
  5. #include <commdlg.h>
  6. #include <io.h>
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <direct.h>
  11. #include <string.h>
  12. #include <ctl3d.h>
  13. #include "appbar.h"
  14.  
  15. /*----------------------------------------------------------------------------*/
  16. /* FUNCTION: OkMsgBox(char *szCaption, char *szFormat, ...)             */
  17. /*                                                                            */
  18. /* PURPOSE:  Display in an OKmessageBox a given text                       */
  19. /*----------------------------------------------------------------------------*/
  20. VOID OkMsgBox(char *szCaption, char *szFormat, ...)
  21.     {
  22.     char *pArguments;
  23.  
  24.     pArguments = (char *) &szFormat + sizeof(szFormat);
  25.     vsprintf(szBuffer, szFormat, pArguments);
  26.     if(AppSound.EnableSound != 0)
  27.     if(stricmp(AppSound.ErrorMessage, "<none>") != 0)
  28.         sndPlaySound(AppSound.ErrorMessage, SND_ASYNC | SND_NODEFAULT);
  29.     MessageBox(NULL, szBuffer, szCaption, MB_OK);
  30.     }
  31.  
  32. /*----------------------------------------------------------------------------*/
  33. /* FUNCTION: ErrorMsgBox(char *szCaption, char *szFormat, ...)             */
  34. /*                                                                            */
  35. /* PURPOSE:  Display in an ErrormessageBox a given text                       */
  36. /*----------------------------------------------------------------------------*/
  37. VOID ErrorMsgBox(char *szCaption, char *szFormat, ...)
  38.     {
  39.     char *pArguments;
  40.  
  41.     pArguments = (char *) &szFormat + sizeof(szFormat);
  42.     vsprintf(szBuffer, szFormat, pArguments);
  43.     if(AppSound.EnableSound != 0)
  44.     if(stricmp(AppSound.ErrorMessage, "<none>") != 0)
  45.         sndPlaySound(AppSound.ErrorMessage, SND_ASYNC | SND_NODEFAULT);
  46.     MessageBox(NULL, szBuffer, szCaption, MB_OK | MB_ICONEXCLAMATION);
  47.     }
  48.  
  49. /*----------------------------------------------------------------------------*/
  50. /* FUNCTION: IniRead(void)                              */
  51. /*                                                                            */
  52. /* PURPOSE:  Read settings in the appbar.ini file.                  */
  53. /*----------------------------------------------------------------------------*/
  54. VOID PASCAL IniRead(VOID)
  55.     {
  56.     int i;
  57.  
  58.     // set settings of AppEmptyButton
  59.     AppEmptyButton = InitButton();
  60.  
  61.     AppSystem = ReadSystemIni();
  62.     AppSound = ReadSoundIni();
  63.  
  64.     if(AppSystem.Border < 3)
  65.     AppSystem.Border = 0;
  66.  
  67.     if(AppSystem.Top > GetSystemMetrics(SM_CYSCREEN))
  68.     AppSystem.Top = -1;
  69.  
  70.     if(AppSystem.Left > GetSystemMetrics(SM_CXSCREEN))
  71.     AppSystem.Left = -1;
  72.  
  73.     for(i=0;i<AppSystem.Buttons;i++)
  74.     {
  75.     AppButton[i] = ReadButtonIni(i, (LPSTR) INI_BUTTON, (LPSTR) INI_FILE);
  76.     AppButton[i].hWndApp = NULL;
  77.     if(AppSystem.CloseAll == 0)
  78.         AppButton[i].Close = FALSE;
  79.     AppButton[i].ProgStatus = NOTALIVE; // no app exists yet
  80.     }
  81.     }
  82.  
  83. /*--------------------------------------------------------------------------*/
  84. APPMAXSIZE CalculateAppMaxSize(VOID)
  85.     {
  86.     int xScreen, yScreen, xAppBar, yAppBar, Rows;
  87.     DWORD xMax = 0, yMax = 0;
  88.     APPMAXSIZE AppBarSize, AppSizeX, AppSizeY;
  89.  
  90.    xScreen = GetSystemMetrics(SM_CXSCREEN);
  91.    yScreen = GetSystemMetrics(SM_CYSCREEN);
  92.    if(AppSystem.Left == -1)
  93.     xAppBar = xScreen - (AppWindow.cxButton+AppSystem.Border)*AppWindow.nColumns - AppSystem.Border;
  94.     else
  95.     xAppBar = AppSystem.Left;
  96.     if(AppSystem.Top == -1)
  97.     yAppBar = 0;
  98.     else
  99.     yAppBar = AppSystem.Top;
  100.  
  101.     // calculate the size of AppBar.
  102.     Rows = AppWindow.nButtons/AppWindow.nColumns;
  103.     AppBarSize.width = AppWindow.cxButton*AppWindow.nColumns;
  104.     AppBarSize.width += (AppWindow.nColumns+1)*AppSystem.Border;
  105.     AppBarSize.height = AppWindow.cyButton*Rows + (Rows+1)*AppSystem.Border;
  106.     AppBarSize.left = xAppBar;
  107.     AppBarSize.top = yAppBar;
  108.  
  109.     // determine largest left space in X direction
  110.     if(AppBarSize.left >= (xScreen -(AppBarSize.left+AppBarSize.width)))
  111.     {
  112.     // largest x-space is to the left of AppBar
  113.     xMax = AppBarSize.left;
  114.     AppSizeX.left = 0;
  115.     AppSizeX.top = 0;
  116.     AppSizeX.width = AppBarSize.left;
  117.     AppSizeX.height = yScreen;
  118.     }
  119.     else
  120.     {
  121.     // largest x-space is to the right of AppBar
  122.     xMax = (xScreen -(AppBarSize.left+AppBarSize.width));
  123.     AppSizeX.left = AppBarSize.left + AppBarSize.width;
  124.     AppSizeX.top = 0;
  125.     AppSizeX.width = xScreen -(AppBarSize.left+AppBarSize.width);
  126.     AppSizeX.height = yScreen;
  127.     }
  128.     if(AppBarSize.top >= (yScreen -(AppBarSize.top+AppBarSize.height)))
  129.     {
  130.     // largest y-space is above AppBar
  131.     yMax = AppBarSize.top;
  132.     AppSizeY.left = 0;
  133.     AppSizeY.top = 0;
  134.     AppSizeY.width = xScreen;
  135.     AppSizeY.height = AppBarSize.top;
  136.     }
  137.     else
  138.     {
  139.     // largest y-space is under AppBar
  140.     yMax = (yScreen -(AppBarSize.top+AppBarSize.height));
  141.     AppSizeY.left = 0;
  142.     AppSizeY.top = AppBarSize.top + AppBarSize.height;
  143.     AppSizeY.width = xScreen;
  144.     AppSizeY.height = yScreen - (AppBarSize.top+AppBarSize.height);
  145.     }
  146.  
  147.     xMax *= yScreen;
  148.     yMax *= xScreen;
  149.     if(xMax >= yMax)
  150.     return AppSizeX;
  151.     else
  152.     return AppSizeY;
  153.     }
  154.  
  155. /*-------------------------------------------------------------------------*/
  156. VOID SetNormalChildCursor(VOID)
  157.     {
  158.     SetClassWord(hWndButton[0], GCW_HCURSOR,
  159.          (WPARAM) LoadCursor(NULL, IDC_ARROW));
  160.     }
  161.  
  162. /*-------------------------------------------------------------------------*/
  163. VOID SetShuffleChildCursor(VOID)
  164.     {
  165.     SetClassWord(hWndButton[0], GCW_HCURSOR,
  166.          (WPARAM) LoadCursor(hInst, "AppShuffle"));
  167.     }
  168.  
  169. /*-------------------------------------------------------------------------*/
  170. void InitTip(void)
  171.     {
  172.     int i;
  173.  
  174.     // if Tip.exe is used on AppBar, launch it to initialize it.
  175.     for(i=0;i<AppSystem.Buttons;i++)
  176.     {
  177.     if(strstr((char *)AnsiLower((LPSTR)AppButton[i].ProgName), "tip.exe") != NULL)
  178.         ShellExecute(hWndMain, "open", AppButton[i].ProgName, "/setup", NULL, SW_SHOWNORMAL);
  179.     }
  180.     }
  181.  
  182. /*-------------------------------------------------------------------------*/
  183. BOOL IsAppTip(int AppNumber)
  184.     {
  185.     // if App[AppNumber] is Tip.exe, then return TRUE.
  186.     if(strstr((char *)AnsiLower((LPSTR)AppButton[AppNumber].ProgName), "tip.exe") != NULL)
  187.     return TRUE;
  188.     else
  189.     return FALSE;
  190.     }
  191.  
  192. /*-------------------------------------------------------------------------*/
  193. void TipSetIcon(WORD iIcon, HICON *hIcon)
  194.     {
  195.     int i;
  196.  
  197.     for(i=0;i<AppSystem.Buttons;i++)
  198.     {
  199.     if(strstr((char *)AnsiLower((LPSTR)AppButton[i].ProgName), "tip.exe") != NULL)
  200.         {
  201.         hIcon[i] = ExtractIcon(hInst, AppButton[i].ProgName,iIcon);
  202.         if(hIcon[i] == (HICON) 1)
  203.         hIcon[i] = NULL;
  204.         InvalidateRect(hWndButton[i+FirstAppButton], NULL, FALSE);
  205.         UpdateWindow(hWndButton[i+FirstAppButton]);
  206.         }
  207.     }
  208.     }
  209.  
  210. /*-------------------------------------------------------------------------*/
  211. void LoadAllButtonIcons(HICON *hIcon)
  212.     {
  213.     int i;
  214.  
  215.     for(i=0;i<AppSystem.Buttons;i++)
  216.     {
  217.     hIcon[i] = ExtractIcon(hInst, AppButton[i].IcoName, AppButton[i].IconNumber);
  218.     if(hIcon[i] == (HICON) 1)
  219.         {
  220.         hIcon[i] = NULL;
  221.         OkMsgBox("AppBar - Initialisation", "No Icons found in %s", AppButton[i].IcoName);
  222.         }
  223.     }
  224.     }
  225.  
  226. /*-------------------------------------------------------------------------*/
  227. void LoadAppBarResources(void)
  228.     {
  229.     hQuickLoad = LoadIcon(hInst, MAKEINTRESOURCE(1004));
  230.  
  231.     if(!AppSystem.BigButtons)
  232.     {
  233.     hSystem       = LoadIcon(hInst, MAKEINTRESOURCE(1000));
  234.     hPressed   = LoadIcon(hInst, MAKEINTRESOURCE(1002));
  235.     hBlank       = LoadIcon(hInst, MAKEINTRESOURCE(1003));
  236.     hKeybOn       = LoadIcon(hInst, MAKEINTRESOURCE(1005));
  237.     }
  238.  
  239.     if(AppSystem.BigButtons)
  240.     {
  241.     hSystem2  = LoadIcon(hInst, MAKEINTRESOURCE(1008));
  242.     hPressed2 = LoadIcon(hInst, MAKEINTRESOURCE(1007));
  243.     hbBlank   = LoadBitmap(hInst, "BlankBMP");
  244.     hbKeyb      = LoadBitmap(hInst, "KeybBMP");
  245.     hbPressed = LoadBitmap(hInst, "PressBMP");
  246.     }
  247.     }
  248.  
  249. /*-------------------------------------------------------------------------*/
  250. void FreeAppBarResources(void)
  251.     {
  252.     if(AppSystem.BigButtons)
  253.     {
  254.  
  255.         DeleteBitmap(hbBlank);
  256.     DeleteBitmap(hbKeyb);
  257.     DeleteBitmap(hbPressed);
  258.     }
  259.     }
  260.  
  261. /*--------------------------------------------------------------------------*/
  262. BOOL IsAppBarShell(VOID)
  263.     {
  264.     char ShellString[MAXFILECHARS];
  265.  
  266.     GetPrivateProfileString("boot", "shell", "  ", ShellString, MAXFILECHARS-1, "system.ini");
  267.     if(strstr((char *) AnsiLower((char FAR *)ShellString),"appbar.exe"))
  268.     return TRUE;
  269.     else
  270.     return FALSE;
  271.     }
  272.